// 工单选择
<template>
  <div>
    <el-input v-model="dealerNoInName" readonly>
      <i slot="suffix" class="el-input__icon el-icon-circle-plus" @click="openDia"/>
      <i slot="suffix" class="el-input__icon el-icon-error" @click="changeDE" />
    </el-input>
    <!-- 弹框 -->
    <el-dialog
      v-dialogDrag
      ref="dialog"
      :visible.sync="dialogVisible"
      :append-to-body="true"
      :show-close="false"
      :before-close="dialogCancel"
      :close-on-click-modal="false"
      title="供应商选择"
      width="75%"
    >
      <div class="searchform">
        <!-- 查询条件 -->
        <el-form ref="searchForm" :model="search" size="mini" label-width="90px">
          <el-row :gutter="6">
            <el-col :xs="24" :sm="12" :md="8">
              <el-form-item prop="provideCode" label="供应商代码">
                <el-input v-model="search.provideCode" clearable />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8">
              <el-form-item prop="provideName" label="供应商名称">
                <el-input v-model="search.provideName" clearable />
              </el-form-item>
            </el-col>
            <div style="text-align:right">
              <el-button type="primary" icon="el-icon-search" @click="searchRole">查询</el-button>
              <el-button icon="el-icon-refresh" @click="resetForm('searchForm')">重置</el-button>
            </div>
          </el-row>
        </el-form>
      </div>
      <div class="table">
        <el-table
          v-loading="load"
          ref="roleTable"
          :data="list"
          tooltip-effect="dark"
          highlight-current-row
          stripe
          border
          @current-change="select"
          @selection-change="select"
        >
          <el-table-column v-if="allowRadio" type="selection" width="40"/>
          <el-table-column label="序号" type="index" min-width="50"/>
          <el-table-column prop="PROVIDER_CODE" label="供应商代码" min-width="100"/>
          <el-table-column prop="PROVIDER_NAME" label="供应商名称" min-width="120"/>
        </el-table>

        <!-- 分页 -->
        <div style="text-align:right">
          <Pagination
            :data="page"
            @change-size="handleSizeChange"
            @change-page="handleCurrentChange"
          />
        </div>
      </div>
      <div slot="footer" style="text-align:center" class="dialog-footer">
        <el-button type="text">
          <i class="el-icon-search magnifier" />
        </el-button>
        <el-button type="primary" @click="req">确 定</el-button>
        <el-button @click="dialogCancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  queryProvider
} from '@/api/part/dms/basedata/baseCommon'
import rSelect from '@/components/Select/Select'
import Pagination from '@/components/Pagination'
import formMixins from '@/mixins/formMixins'

export default {
  name: 'SelectProvider',
  components: {
    Pagination,
    rSelect
  },
  mixins: [formMixins],
  props: {
    dealerNoInName: String,
    allowRadio: false
  },
  data() {
    return {
      list: [],
      load: false,
      page: {},
      multipleSelection: [],
      search: {
        limit: 10,
        pageNum: 1,
        provideCode: '',
        provideName: ''
      },
      dialogVisible: false
    }
  },
  mounted() {},
  methods: {
    openDia() {
      this.dialogVisible = true
      this.searchRole()
    },
    // 查询界面
    searchRole() {
      this.load = true
      queryProvider(this.search)
        .then(res => {
          this.list = res.rows
          this.page = res
          this.load = false
        })
        .catch(err => {
          this.load = false
        })
    },
    select(val) {
      if (val == null) {
        this.multipleSelection = []
      } else {
        this.multipleSelection = val
      }
    },
    handleSizeChange(size) {
      this.search.limit = size
      this.searchRole()
    },
    handleCurrentChange(page) {
      this.search.pageNum = page
      this.searchRole()
    },
    // 确定
    req() {
      if (this.multipleSelection.length === 0) {
        this.$message({
          type: 'info',
          message: '请选择数据!'
        })
      } else {
        this.$emit('getProvider', this.multipleSelection)
        this.dialogVisible = false
      }
    },
    changeDE() {
      this.$emit('getProvider', {})
    },
    dialogCancel() {
      this.dialogVisible = false
    }
  }
}
</script>

<style scoped>
</style>
